/*
 * Copyright 2020 HPB Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hpb.bc.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.hpb.bc.entity.apiKey.View;
import com.hpb.bc.util.apiKey.Tools;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiKey extends BaseEntity {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.id
     *
     * @mbg.generated
     */
    @JsonProperty("id")
    private String id;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.api_key
     *
     * @mbg.generated
     */
    @JsonProperty("apiKey")
    @JsonView(View.Public.class)
    private String apiKey;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.private_key
     *
     * @mbg.generated
     */
    @JsonProperty("privateKey")
    private String privateKey;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.usage_limit
     *
     * @mbg.generated
     */
    @JsonProperty("usageLimit")
    @JsonView(View.Public.class)
    private Long usageLimit;


    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.app_name
     *
     * @mbg.generated
     */
    @JsonProperty("appName")
    @JsonView(View.Public.class)
    private String appName;


    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.registration_date
     *
     * @mbg.generated
     */
    @JsonProperty("registrationDate")
    @JsonView(View.Public.class)
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    private Date registrationDate;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.activation_date
     *
     * @mbg.generated
     */
    @JsonProperty("activationDate")
    @JsonView(View.Public.class)
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    private Date activationDate;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.email
     *
     * @mbg.generated
     */
    @JsonProperty("email")
    @JsonView(View.Public.class)
    private String email;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.level
     *
     * @mbg.generated
     */
    @JsonProperty("levelStr")
    private String levelStr;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.first_name
     *
     * @mbg.generated
     */

    @JsonProperty("firstName")
    @JsonView(View.Public.class)
    private String firstName;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.last_name
     *
     * @mbg.generated
     */

    @JsonProperty("lastName")
    @JsonView(View.Public.class)
    private String lastName;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.company
     *
     * @mbg.generated
     */
    @JsonProperty("company")
    @JsonView(View.Public.class)
    private String company;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.website
     *
     * @mbg.generated
     */
    @JsonProperty("website")
    @JsonView(View.Public.class)
    private String website;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.sector
     *
     * @mbg.generated
     */
    @JsonProperty("sector")
    @JsonView(View.Public.class)
    private String sector;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.deprecation_date
     *
     * @mbg.generated
     */
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    @JsonProperty("deprecationDate")
    @JsonView(View.Public.class)
    private Date deprecationDate;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.lastaccess_date
     *
     * @mbg.generated
     */
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    @JsonProperty("lastAccessDate")
    @JsonView(View.Public.class)
    private Date lastaccessDate;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column api_key_1.usage
     *
     * @mbg.generated
     */
    @JsonProperty("usageNumber")
    @JsonView(View.Public.class)
    private Long usageNumber;

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.id
     *
     * @return the value of api_key_1.id
     * @mbg.generated
     */
    public String getId() {
        return id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.id
     *
     * @param id the value for api_key_1.id
     * @mbg.generated
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.api_key
     *
     * @return the value of api_key_1.api_key
     * @mbg.generated
     */
    public String getApiKey() {
        return apiKey;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.api_key
     *
     * @param apiKey the value for api_key_1.api_key
     * @mbg.generated
     */
    public void setApiKey(String apiKey) {
        this.apiKey = apiKey == null ? null : apiKey.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.private_key
     *
     * @return the value of api_key_1.private_key
     * @mbg.generated
     */
    public String getPrivateKey() {
        return privateKey;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.private_key
     *
     * @param privateKey the value for api_key_1.private_key
     * @mbg.generated
     */
    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey == null ? null : privateKey.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.usage_limit
     *
     * @return the value of api_key_1.usage_limit
     * @mbg.generated
     */
    public Long getUsageLimit() {
        return usageLimit;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.usage_limit
     *
     * @param usageLimit the value for api_key_1.usage_limit
     * @mbg.generated
     */
    public void setUsageLimit(Long usageLimit) {
        this.usageLimit = usageLimit;
    }


    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.app_name
     *
     * @return the value of api_key_1.app_name
     * @mbg.generated
     */
    public String getAppName() {
        return appName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.app_name
     *
     * @param appName the value for api_key_1.app_name
     * @mbg.generated
     */
    public void setAppName(String appName) {
        this.appName = appName == null ? null : appName.trim();
    }


    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.registration_date
     *
     * @return the value of api_key_1.registration_date
     * @mbg.generated
     */
    public Date getRegistrationDate() {
        return registrationDate;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.registration_date
     *
     * @param registrationDate the value for api_key_1.registration_date
     * @mbg.generated
     */
    public void setRegistrationDate(Date registrationDate) {
        this.registrationDate = registrationDate;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.activation_date
     *
     * @return the value of api_key_1.activation_date
     * @mbg.generated
     */
    public Date getActivationDate() {
        return activationDate;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.activation_date
     *
     * @param activationDate the value for api_key_1.activation_date
     * @mbg.generated
     */
    public void setActivationDate(Date activationDate) {
        this.activationDate = activationDate;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.email
     *
     * @return the value of api_key_1.email
     * @mbg.generated
     */
    public String getEmail() {
        return email;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.email
     *
     * @param email the value for api_key_1.email
     * @mbg.generated
     */
    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }


    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.first_name
     *
     * @return the value of api_key_1.first_name
     * @mbg.generated
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.first_name
     *
     * @param firstName the value for api_key_1.first_name
     * @mbg.generated
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName == null ? null : firstName.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.last_name
     *
     * @return the value of api_key_1.last_name
     * @mbg.generated
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.last_name
     *
     * @param lastName the value for api_key_1.last_name
     * @mbg.generated
     */
    public void setLastName(String lastName) {
        this.lastName = lastName == null ? null : lastName.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.company
     *
     * @return the value of api_key_1.company
     * @mbg.generated
     */
    public String getCompany() {
        return company;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.company
     *
     * @param company the value for api_key_1.company
     * @mbg.generated
     */
    public void setCompany(String company) {
        this.company = company == null ? null : company.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.website
     *
     * @return the value of api_key_1.website
     * @mbg.generated
     */
    public String getWebsite() {
        return website;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.website
     *
     * @param website the value for api_key_1.website
     * @mbg.generated
     */
    public void setWebsite(String website) {
        this.website = website == null ? null : website.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.sector
     *
     * @return the value of api_key_1.sector
     * @mbg.generated
     */
    public String getSector() {
        return sector;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.sector
     *
     * @param sector the value for api_key_1.sector
     * @mbg.generated
     */
    public void setSector(String sector) {
        this.sector = sector == null ? null : sector.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.deprecation_date
     *
     * @return the value of api_key_1.deprecation_date
     * @mbg.generated
     */
    public Date getDeprecationDate() {
        return deprecationDate;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.deprecation_date
     *
     * @param deprecationDate the value for api_key_1.deprecation_date
     * @mbg.generated
     */
    public void setDeprecationDate(Date deprecationDate) {
        this.deprecationDate = deprecationDate;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column api_key_1.lastaccess_date
     *
     * @return the value of api_key_1.lastaccess_date
     * @mbg.generated
     */
    public Date getLastaccessDate() {
        return lastaccessDate;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column api_key_1.lastaccess_date
     *
     * @param lastaccessDate the value for api_key_1.lastaccess_date
     * @mbg.generated
     */
    public void setLastaccessDate(Date lastaccessDate) {
        this.lastaccessDate = lastaccessDate;
    }


    public String getLevelStr() {
        return levelStr;
    }

    public void setLevelStr(String levelStr) {
        this.levelStr = levelStr;
    }

    public Long getUsageNumber() {
        return usageNumber;
    }

    public void setUsageNumber(Long usageNumber) {
        this.usageNumber = usageNumber;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        ApiKey other = (ApiKey) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getApiKey() == null ? other.getApiKey() == null : this.getApiKey().equals(other.getApiKey()))
                && (this.getPrivateKey() == null ? other.getPrivateKey() == null : this.getPrivateKey().equals(other.getPrivateKey()))
                && (this.getUsageLimit() == null ? other.getUsageLimit() == null : this.getUsageLimit().equals(other.getUsageLimit()))
                && (this.getAppName() == null ? other.getAppName() == null : this.getAppName().equals(other.getAppName()))
                && (this.getRegistrationDate() == null ? other.getRegistrationDate() == null : this.getRegistrationDate().equals(other.getRegistrationDate()))
                && (this.getActivationDate() == null ? other.getActivationDate() == null : this.getActivationDate().equals(other.getActivationDate()))
                && (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
                && (this.getLevelStr() == null ? other.getLevelStr() == null : this.getLevelStr().equals(other.getLevelStr()))
                && (this.getFirstName() == null ? other.getFirstName() == null : this.getFirstName().equals(other.getFirstName()))
                && (this.getLastName() == null ? other.getLastName() == null : this.getLastName().equals(other.getLastName()))
                && (this.getCompany() == null ? other.getCompany() == null : this.getCompany().equals(other.getCompany()))
                && (this.getWebsite() == null ? other.getWebsite() == null : this.getWebsite().equals(other.getWebsite()))
                && (this.getSector() == null ? other.getSector() == null : this.getSector().equals(other.getSector()))
                && (this.getDeprecationDate() == null ? other.getDeprecationDate() == null : this.getDeprecationDate().equals(other.getDeprecationDate()))
                && (this.getLastaccessDate() == null ? other.getLastaccessDate() == null : this.getLastaccessDate().equals(other.getLastaccessDate()))
                && (this.getUsageNumber() == null ? other.getUsageNumber() == null : this.getUsageNumber().equals(other.getUsageNumber()));
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table api_key_1
     *
     * @mbg.generated
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getApiKey() == null) ? 0 : getApiKey().hashCode());
        result = prime * result + ((getPrivateKey() == null) ? 0 : getPrivateKey().hashCode());
        result = prime * result + ((getUsageLimit() == null) ? 0 : getUsageLimit().hashCode());
        result = prime * result + ((getAppName() == null) ? 0 : getAppName().hashCode());
        result = prime * result + ((getRegistrationDate() == null) ? 0 : getRegistrationDate().hashCode());
        result = prime * result + ((getActivationDate() == null) ? 0 : getActivationDate().hashCode());
        result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
        result = prime * result + ((getLevelStr() == null) ? 0 : getLevelStr().hashCode());
        result = prime * result + ((getFirstName() == null) ? 0 : getFirstName().hashCode());
        result = prime * result + ((getLastName() == null) ? 0 : getLastName().hashCode());
        result = prime * result + ((getCompany() == null) ? 0 : getCompany().hashCode());
        result = prime * result + ((getWebsite() == null) ? 0 : getWebsite().hashCode());
        result = prime * result + ((getSector() == null) ? 0 : getSector().hashCode());
        result = prime * result + ((getDeprecationDate() == null) ? 0 : getDeprecationDate().hashCode());
        result = prime * result + ((getLastaccessDate() == null) ? 0 : getLastaccessDate().hashCode());
        result = prime * result + ((getUsageNumber() == null) ? 0 : getUsageNumber().hashCode());
        return result;
    }

    /*    ApiKey apikey = new ApiKey(newApiKey,
                Tools.generatePassPhrase(10),
                apikeyCreate.getFirstName(),
                apikeyCreate.getLastName(),
                apikeyCreate.getEmail()
        );*/
    public ApiKey(String apiKey, String privateKey, String firstName, String lastName, String email) {
        this.apiKey = apiKey;
        this.privateKey = privateKey;
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
    }

    public ApiKey() {
    }

    @Override
    public String toString() {
        return "ApiKey{" +
                "id='" + id + '\'' +
                ", apiKey='" + apiKey + '\'' +
                ", privateKey='" + privateKey + '\'' +
                ", usageLimit=" + usageLimit +
                ", appName='" + appName + '\'' +
                ", registrationDate=" + registrationDate +
                ", activationDate=" + activationDate +
                ", email='" + email + '\'' +
                ", levelStr='" + levelStr + '\'' +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", company='" + company + '\'' +
                ", website='" + website + '\'' +
                ", sector='" + sector + '\'' +
                ", deprecationDate=" + deprecationDate +
                ", lastaccessDate=" + lastaccessDate +
                ", usageNumber=" + usageNumber +
                '}';
    }
}